<#include "include/_meta.html"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户编辑页面</title>
</head>
<body>
	<div class="page-container" id="listResult">
      <#list accounts as account>
				<form onsubmit="return false" class="form form-horizontal" id="form-article-edit">
					<input type="hidden" name="uid" id="uid" value="${account.uid}">
					<div class="row cl">
						<label for="username" class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>账户名称：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" class="input-text" value="${account.username!}"
							       placeholder="请输入账户名" id="username" name="username">
						</div>
					</div>
					<div class="row cl">
						<label for="nickname" class="form-label col-xs-4 col-sm-2">账户昵称：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" name="nickname" id="nickname" placeholder="请输入昵称"
							       value="${account.nickname!}" class="input-text">
						</div>
					</div>
					<div class="row cl">
						<label for="realname" class="form-label col-xs-4 col-sm-2">
							<span class="c-red">*</span>真实姓名：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" name="realname" id="realname" placeholder="请输入真实姓名"
							       value="${account.realname!}" class="input-text">
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-4 col-sm-2">
							<span class="c-red">*</span>手机号码：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" name="mobile" id="mobile" placeholder="请输入手机号码"
							       value="${account.mobile!}" class="input-text">
						</div>
					</div>
					<div class="row cl">
						<label for="email" class="form-label col-xs-4 col-sm-2">账户邮箱：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" name="email" id="email" placeholder="请输入账户邮箱"
							       value="${account.email!}" class="input-text">
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>员工工号：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" name="personid" id="personid" placeholder="请输入员工工号"
							       value="${account.personid!}" class="input-text">
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-4 col-sm-2">用户状态：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="radio" name="userstate" <#if account.userstate == 1>checked</#if>
							       value="1">&nbsp;正常&nbsp;&nbsp;&nbsp;
							<input type="radio" name="userstate" <#if account.userstate == 2>checked</#if>
							       value="2">&nbsp;锁定
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>所属部门：</label>
						<div class="formControls col-xs-8 col-sm-9">
          <span class="select-box">
            <select class="select" name="deptcode">
	            <#if !account.deptcode??>
		            <option value="-1">请选择</option>
		            <#list depts as dept>
		            <option value="${dept.deptid}">${dept.deptname}</option>
              </#list>
		            <#else>
                  <#list depts as dept>
				            <option value="${dept.deptid}"
                            <#if dept.deptid == account.deptcode>selected</#if>>${dept.deptname}</option>
                  </#list>
              </#if>
            </select>
          </span>
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>角色：</label>
						<div class="formControls col-xs-8 col-sm-9">
          <span class="select-box">
				<select class="select" name="rolecode">
					<#if !account.rolecode??>
						<option value="-1">请选择</option>
					<#list roles as role>
						<option value="${role.roleid}">${role.rolename}</option>
          </#list>
							<#else>
              <#list roles as role>
                  <#if role.roleid?c == account.rolecode>
										<option value="${role.roleid}" selected>${role.rolename}</option>
			            <#else >
										<option value="${role.roleid}">${role.rolename}</option>
                  </#if>
              </#list>
          </#if>
        </select>
				</span>
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-4 col-sm-3">备注：</label>
						<div class="formControls col-xs-8 col-sm-9">
          <textarea id="remark" name="remark" cols="" rows="" class="textarea"
                    placeholder="说点什么...100个字符以内" dragonfly="true"
                    onKeyUp="textarealength(this,100)">${account.remark!}</textarea>
							<p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p>
						</div>
					</div>
					<div>
						<input type="submit" class="btn btn-success" value="提交">
						<input type="button" id="cancelBtn" class="btn btn-default" value="取消">
					</div>
				</form>
      </#list>
	</div>
    <#include "include/_footer.html"/>
	<script type="text/javascript">

    let closeWin = function () {
      let index = parent.layer.getFrameIndex(window.name);
      layer.alert('修改成功');
      parent.show();
      parent.layer.close(index);
    }

    $('#form-article-edit').validate({
      onsubmit: true, //是否提交时验证
      onkeyup: false, //是否在敲击键盘时验证
      rules: {
        username: {
          required: true,
          remote: {
            url: '/accounts/isUsername',
            dataType: 'json',
            type: 'post',
            data: {
              username: function () {
                return $('#username').val();
              },
              uid: function () {
                return $('#uid').val();
              }
            }
          }
        },
        password: {
          required: true
        },
        password_again: {
          equalTo: $('#userpwd')
        },
        realname: {
          required: true
        },
        mobile: {
          required: true
        },
        personid: {
          required: true
        },
        deptcode: {
          isIntGtZero: true
        },
        rolecode: {
          isIntGtZero: true
        },
        remark: {
          maxlength: 100
        }
      },
      messages: {
        username: {
          required: '',
          remote: '用户名重复'
        },
        password: {
          required: ''
        },
        password_again: {
          equalTo: ''
        },
        realname: {
          required: ''
        },
        mobile: {
          required: ''
        },
        personid: {
          required: ''
        },
        deptcode: {
          isIntGtZero: '请选择所属部门'
        },
        rolecode: {
          isIntGtZero: '请选择角色'
        }
      },
      submitHandler: function () {

        $.ajax({
          url: '/accounts/editAccount',
          type: 'post',
          data: $('#form-article-edit').serialize(),
          dataType: 'json',
          success: function (flag) {
            if (flag) {
              closeWin();
            } else {
              layer.alert('添加失败，请稍后再试');
            }
          }
        });
      }
    });

    $('#cancelBtn').on('click', function () {
      closeWin();
    });
	</script>
</body>
</html>